package com.jxb;

import com.jxb.protobuf.RPCDateRequest;
import com.jxb.protobuf.RPCDateResponse;
import com.jxb.protobuf.RPCDateServiceGrpc;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;

public class GRPCClient {

    private static final String host = "localhost";
    private static final int serverPort = 9999;

    public static void main(String[] args) {
        //拿到通信channel
        ManagedChannel channel = ManagedChannelBuilder.forAddress(host, serverPort)
                .usePlaintext()
                .build();

        try {
            //拿到stub对象
            RPCDateServiceGrpc.RPCDateServiceBlockingStub stub = RPCDateServiceGrpc.newBlockingStub(channel);
            //构建请求
            RPCDateRequest build = RPCDateRequest.newBuilder().setUserName("123").build();
            //发送请求
            RPCDateResponse date = stub.getDate(build);
            System.out.println("输出结果："+date.getServerDate());
        }finally {
            channel.shutdown();
        }
    }

}
